package com.ht.medicaltreatment.view

import android.content.Context
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.listener.OnItemClickListener
import com.ht.medicaltreatment.R
import com.ht.medicaltreatment.adapter.AddressListAdapter
import kotlinx.android.synthetic.main.dialog_address_list_layout.*

class AddressListDialog(context: Context):BaseDialog(context), OnItemClickListener {
    override fun getLayoutRes() = R.layout.dialog_address_list_layout

    private val adapter = AddressListAdapter()
    private var onClick:(String)->Unit={}
    init {
        recyclerView.layoutManager = LinearLayoutManager(context)
        recyclerView.adapter = adapter
        adapter.setOnItemClickListener(this)
    }

    fun show(list:ArrayList<String>,OnClick:(String)->Unit) {
        super.show()
        adapter.setNewInstance(list)
        onClick = OnClick
    }

    override fun onItemClick(adapter: BaseQuickAdapter<*, *>, view: View, position: Int) {
        onClick(adapter.getItem(position)as String)
        dismiss()
    }
}